students= [
    ('jane', 'B', 12),
    ('john', 'A', 15),
    ('dave', 'B', 10),
]
print(sorted(students, key=lambda x: x[2]))
class Student:
    def __init__(self, name, grade, age):
        self.name = name
        self.grade = grade
        self.age = age

    def __repr__(self):
        return repr((self.name, self.grade, self.age))

student = Student('john', 'A', 15)
student_objects = [
    Student('john', 'A', 15),
    Student('jane', 'B', 12),
    Student('dave', 'B', 10),
]
print(sorted(student_objects,key=lambda student:student.age))
from operator import itemgetter, attrgetter
print(sorted(students, key=itemgetter(0)))
print(sorted(students, key=itemgetter(1)))
print(sorted(students, key=itemgetter(2)))
print(sorted(student_objects,key=attrgetter('age')))
print(sorted(students, key=itemgetter(1,2)))
print(sorted(students, key=lambda x: (x[1],-x[2])))
print(sorted(student_objects, key=attrgetter('grade', 'age'),reverse=True))